package com.lsh.payment.core.dao.mybatis.handler;

import org.apache.ibatis.jdbc.RuntimeSqlException;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LongTypeHandler implements TypeHandler<Object> {

    @Override
    public void setParameter(PreparedStatement ps, int i, Object value, JdbcType jdbcType) throws SQLException {
        Long longValue;
        if (value instanceof Long) {
            longValue = (Long) value;
        } else {
            longValue = Long.parseLong(value.toString());
        }
        ps.setLong(i, longValue);
    }

    @Override
    public Long getResult(ResultSet rs, String columnName) throws SQLException {
        throw new RuntimeSqlException();
    }

    @Override
    public Long getResult(ResultSet rs, int columnIndex) throws SQLException {
        throw new RuntimeSqlException();
    }

    @Override
    public Long getResult(CallableStatement cs, int columnIndex) throws SQLException {
        throw new RuntimeSqlException();
    }
}
